package com.zichuan.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zichuan
 * @version 1.0
 * @Package : com.zichuan.config
 * @Description : TODO
 * @Create on : 2025/2/17 19:20
 */
@Slf4j
@Configuration
public class RabbitmqConfig {

    @Value("${app.exchangeName}")
    private String exchangeName;

    @Value("${app.queueName}")
    private String queueName;


    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(exchangeName);
    }

    @Bean
    public Queue queueA(){
        // public Queue(String name, boolean durable, boolean exclusive, boolean autoDelete, @Nullable Map<String, Object> arguments) {
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-overflow","reject-publish");
        arguments.put("x-max-length",5);
        return new Queue(queueName,true,false,false,arguments);
    }

    @Bean
    public Binding bindingA(DirectExchange directExchange,Queue queueA){
        return BindingBuilder.bind(queueA).to(directExchange).with("order");
    }

}
